package com.xb.cloud.product.service.business.dao.impl;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.alibaba.fastjson.JSON;
import com.xb.cloud.common.mongo.client.SimpleMongoClient;
import com.xb.cloud.product.merchant.service.client.bo.ProductMongoBo;
import com.xb.cloud.product.merchant.service.client.bo.ProductShopSeriesMongoBo;
import com.xb.cloud.product.service.business.dao.ProductMongoDao;

@Repository("productMongoDao")
public class ProductMongoDaoImpl implements ProductMongoDao {
	private static final Logger logger = LoggerFactory.getLogger(ProductMongoDaoImpl.class);

	@Resource
	private SimpleMongoClient bMongoClient;

	public boolean save(ProductMongoBo pmongo) {
		boolean success = true;
		try {
			Object key = bMongoClient.save(pmongo);
			if (key == null || key.toString().isEmpty()) {
				success = false;
			}
		} catch (Exception e) {
			logger.error(JSON.toJSONString(pmongo), e);
			success = false;
		}

		return success;
	}

	public ProductMongoBo findById(Long id) {
		return bMongoClient.findById(ProductMongoBo.class, id);
	}

	/**
	 * 保存系列品 ： 产品店铺系列组合Bo
	 * 
	 * @param pmongo
	 * @return
	 */
	public boolean saveProductShopSeriesMongoBo(ProductShopSeriesMongoBo productShopSeriesMongoBo) {
		boolean success = true;
		try {
			Object key = bMongoClient.save(productShopSeriesMongoBo);
			if (key == null || key.toString().isEmpty()) {
				success = false;
			}
		} catch (Exception e) {
			logger.error(JSON.toJSONString(productShopSeriesMongoBo), e);
			success = false;
		}

		return success;
	}

	/**
	 * 根据ProductId + ShopId 查询 产品店铺系列组合Bo
	 * @param id
	 * @return
	 */
	public ProductShopSeriesMongoBo findProductShopSeriesMongoBoById(String id) {
		return bMongoClient.findById(ProductShopSeriesMongoBo.class, id);
	}

}
